home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / GCC / CLIB / !clib / h / kernel < prev    next >
Text File  |  1997-04-06  |  8KB  |  236 lines

  1. /* kernel.h
  2.  
  3.    For use with the GNU compilers and the SharedCLibrary.
  4.    (c) Copyright 1997, Nick Burrett.  */
  5.  
  6. #ifndef __KERNEL_H
  7. #define __KERNEL_H
  8.  
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12.  
  13. /* GCC has various useful declarations that can be made with the
  14.    __attribute__ syntax.  Disable its use for other compilers.  */
  15. #ifndef __GNUC__
  16. #ifndef __attribute__
  17. #define __attribute__(x) /* Ignore.  */
  18. #endif
  19. #endif
  20.  
  21. typedef struct
  22. {
  23.   int errnum;
  24.   char errmess[252];
  25. } _kernel_oserror;
  26.  
  27. /* Stack management functions.  */
  28.  
  29. typedef struct stack_chunk
  30. {
  31.   unsigned long sc_mark; /* == 0xf60690ff */
  32.   struct stack_chunk *sc_next, *sc_prev;
  33.   unsigned long sc_size;
  34.   int (*sc_deallocate)();
  35. } _kernel_stack_chunk;
  36.  
  37. /* Return a pointer to the current stack chunk.  */
  38. extern _kernel_stack_chunk *_kernel_current_stack_chunk (void);
  39.  
  40. typedef struct
  41. {
  42.   int r4, r5, r6, r7, r8, r9;
  43.   int fp, sp, pc, sl;
  44.   int f4[3], f5[3], f6[3], f7[3];
  45. } _kernel_unwindblock;
  46.  
  47. /* Unwind the call stack one level. Return: >0 on success,
  48.    0 if stack end has been reached, <0 any other failures.  */
  49. extern int _kernel_unwind(_kernel_unwindblock *inout, char **language);
  50.  
  51. /* Program environment functions.  */
  52.  
  53. /* Return a pointer to the name of the function that contains the
  54.    address 'pc' (or zero if no name can be found).  */
  55. extern char *_kernel_procname (int pc);
  56.  
  57. /* Return a pointer to the name of the language that the address
  58.    'pc' lies within. Zero if the language is unknown. */
  59. extern char *_kernel_language (int pc);
  60.  
  61. /* Return a pointer to the command string used to run the program.  */
  62. extern char *_kernel_command_string (void);
  63.  
  64. /* Set the return code to be used by _kernel_exit.  */
  65. extern void _kernel_setreturncode (unsigned code);
  66.  
  67. /* Call OS_Exit. Use the return code set by _kernel_setreturncode.  */
  68. extern void _kernel_exit (int) __attribute__ ((__noreturn__));
  69.  
  70. /* Generates an external error.  */
  71. extern void _kernel_raise_error (_kernel_oserror *);
  72.  
  73. /* Reset the InTrapHandler flag to prevent recursive traps.  */
  74. extern void _kernel_exittraphandler (void);
  75.  
  76. /* Returns 6 for RISC OS.  */
  77. extern int _kernel_hostos (void);
  78.  
  79. /* Return non-zero if floating point instructions are available.  */
  80. extern int _kernel_fpavailable (void);
  81.  
  82. /* Return the last OS error since the last time _kernel_last_oserror
  83.    was called. Return zero if no errors have occurred.  */
  84. extern _kernel_oserror *_kernel_last_oserror (void);
  85.  
  86. /* Read the value of system variable 'name', placing the result in 'buffer'.  */
  87. extern _kernel_oserror *_kernel_getenv(const char *name, char *buffer, unsigned size);
  88.  
  89. /* Set the system variable 'name' with 'value'. If 'value == 0' then
  90.    'name' is deleted.  */
  91. extern _kernel_oserror *_kernel_setenv(const char *name, const char *value);
  92.  
  93. /* Return 1 if there has been an Escape since the previous call to
  94.    _kernel_escape_seen.  */
  95. extern int _kernel_escape_seen (void);
  96.  
  97. /* Enable IRQ interrupts.  This can only be executed within SVC mode.  */
  98. extern void _kernel_irqs_on (void);
  99.  
  100. /* Disable IRQ interrupts.  This can only be executed within SVC mode.  */
  101. extern void _kernel_irqs_off (void);
  102.  
  103. /* Return non-zero if IRQs are disabled.  */
  104. extern int _kernel_irqs_disabled (void);
  105.  
  106. /* General utility functions.  */
  107.  
  108. typedef struct
  109. {
  110.   int r[10];
  111. } _kernel_swi_regs;
  112.  
  113. /* Call the SWI specified by 'no'. 'in' points to a register block for SWI entry.
  114.    'out' points to a register block for SWI exit. The X bit is set by _kernel_swi
  115.    unless bit 31 is set.  */
  116. extern _kernel_oserror *_kernel_swi (int no, _kernel_swi_regs *in,
  117.                                    _kernel_swi_regs *out);
  118.  
  119.  
  120. /* Similar to _kernel_swi but the carry flag status is returned in 'carry'.  */
  121. extern _kernel_oserror *_kernel_swi_c (int no, _kernel_swi_regs *in,
  122.                                      _kernel_swi_regs *out, int *carry);
  123.  
  124. /* Perform an OS_Byte operation.
  125.    R1 is returned in the bottom byte, R2 in the second byte,
  126.    if carry set, then third byte = 1.  */
  127. extern int _kernel_osbyte (int op, int x, int y);
  128.  
  129. /* Read a character from the OS input stream.  */
  130. extern int _kernel_osrdch (void);
  131.  
  132. /* Write a character to the OS output streams.  The return value indicates
  133.    success or failure.  */
  134. extern int _kernel_oswrch(int ch);
  135.  
  136. /* Return the next byte from the file 'handle'. Return -1 on EOF.  */
  137. extern int _kernel_osbget (unsigned handle);
  138.  
  139. /* Write the byte 'ch' to the file 'handle'. Return success or failure.  */
  140. extern int _kernel_osbput (int ch, unsigned handle);
  141.  
  142. typedef struct
  143. {
  144.   void * dataptr;
  145.   int nbytes, fileptr;
  146.   int buf_len;
  147.   char *wild_fld;
  148. } _kernel_osgbpb_block;
  149.  
  150. /* Read/write a number of bytes on file 'handle'. */
  151. extern int _kernel_osgbpb (int op, unsigned handle, _kernel_osgbpb_block *inout);
  152.  
  153. /* Perform an OS_Word operation.  */
  154. extern int _kernel_osword (int op, int *data);
  155.  
  156. /* Open or close a file. Open returns a file handle, close just
  157.    indicates success/failure.  */
  158. extern int _kernel_osfind (int op, char *name);
  159.  
  160. typedef struct
  161. {
  162.   int load, exec;
  163.   int start, end;
  164. } _kernel_osfile_block;
  165.  
  166. /* Perform an OS_File operation. The _kernel_osfile_block provides
  167.    values for registers R2-R5.  */
  168. extern int _kernel_osfile (int op, const char *name, _kernel_osfile_block *inout);
  169.  
  170. /* Perform an OS_Args operation. Generally returns the value in R2, unless
  171.    op = 0.  */
  172. extern int _kernel_osargs (int op, unsigned handle, int arg);
  173.  
  174. /* Call OS_CLI with the string 's'. If another application is called,
  175.    the current application will be closed down.   */
  176. extern int _kernel_oscli (const char *s);
  177.  
  178. /* Call OS_CLI with the string 's'. If chain == 0, then the current
  179.    application is copied away and the new application executed as
  180.    a subprogram. Control will return to the main application once the
  181.    subprogram has completed.
  182.  
  183.    If chain == 1, then _kernel_system will not return.  */
  184. extern int _kernel_system (const char *string, int chain);
  185.  
  186. /* Memory allocation functions.  */
  187.  
  188. /* Tries to allocate a block of size 'words' words. If it fails,
  189.    it allocates the largest possible block.  */
  190. extern unsigned _kernel_alloc (unsigned words, void **block);
  191.  
  192.  
  193. /* Register procedures to be used by the SharedCLibrary when it
  194.    creates to frees memory e.g. on creation of stack chunks.  */
  195. typedef void freeproc (void *);
  196. typedef void *allocproc (unsigned);
  197.  
  198. extern void _kernel_register_allocs (allocproc *malloc, freeproc *free);
  199.  
  200. /* If the heap limit != application limit, then the procedure
  201.    registered here is used to request n bytes from the memory
  202.    allocation routine.  */
  203. typedef int _kernel_ExtendProc (int /* n */, void ** /* p */);
  204.  
  205. _kernel_ExtendProc *_kernel_register_slotextend (_kernel_ExtendProc *proc);
  206.  
  207. /* Language support.  */
  208.  
  209. /* Unsigned divide and remainder function. Returns the remainder in R1. */
  210. extern unsigned
  211. _kernel_udiv (unsigned divisor, unsigned dividend) __attribute__ ((__const__));
  212.  
  213. /* Unsigned remainder function.  */
  214. extern unsigned
  215. _kernel_urem (unsigned divisor, unsigned dividend) __attribute__ ((__const__));
  216.  
  217. /* Unsigned divide and remainder function by 10.
  218.    Returns the remainder in R1. */
  219. extern unsigned _kernel_udiv10 (unsigned dividend) __attribute__ ((__const__));
  220.  
  221. /* Signed divide and remainder function. Returns the remainder in R1. */
  222. extern int _kernel_sdiv (int divisor, int dividend) __attribute__ ((__const__));
  223.  
  224. /* Signed remainder function.  */
  225. extern int _kernel_srem (int divisor, int dividend) __attribute__ ((__const__));
  226.  
  227. /* Signed divide and remainder function by 10.
  228.    Returns the remainder in R1. */
  229. extern int _kernel_sdiv10 (int dividend) __attribute__ ((__const__));
  230.  
  231. #ifdef __cplusplus
  232. }
  233. #endif
  234.  
  235. #endif
  236.